﻿Namespace Load

    ''' <summary>
    ''' ページリスト
    ''' </summary>
    ''' <typeparam name="T"></typeparam>
    ''' <remarks></remarks>
    Public Class PageList(Of T)
        Inherits List(Of T)
        Implements IPageList

        Private _total As Integer
        Public Property Total() As Integer Implements IPageList.Total
            Get
                Return _total
            End Get
            Friend Set(ByVal value As Integer)
                _total = value
            End Set
        End Property

        ''' <summary>
        ''' 全ページ数
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        ReadOnly Property MaxPageNo As Integer
            Get
                Return If(Me.PageSize = 0, 0, Math.Ceiling(Me.Total / Me.PageSize))
            End Get
        End Property

        Private _pageSize As Integer
        ''' <summary>
        ''' ページサイズ
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property PageSize As Integer Implements IPageList.PageSize
            Get
                Return _pageSize
            End Get
            Friend Set(value As Integer)
                _pageSize = value
            End Set
        End Property

        Private _pageNo As Integer
        ''' <summary>
        ''' ページ番号
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks>最小値は1。</remarks>
        Public Property PageNo As Integer Implements IPageList.PageNo
            Get
                Return _pageNo
            End Get
            Friend Set(value As Integer)
                _pageNo = value
            End Set
        End Property

        ''' <summary>
        ''' 前ページがあるかどうかを示します。
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        ReadOnly Property HasPrevious As Boolean
            Get
                Return If(Me.PageNo = 1, False, True)
            End Get
        End Property

        ''' <summary>
        ''' 次ページがあるかどうかを示します。
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        ReadOnly Property HasNext As Boolean
            Get
                Return If(Me.PageNo < Me.MaxPageNo, True, False)
            End Get
        End Property

        Public Function GetPreviousPageNo() As Integer
            If Me.HasPrevious = False Then Return 1
            Return Me.PageNo - 1
        End Function

        Public Function GetNextPageNo() As Integer
            If Me.HasNext = False Then Return Me.MaxPageNo
            Return Me.PageNo + 1
        End Function

    End Class

End Namespace
